#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;
const int MAXT = 10;

int T;

namespace Solve
{
  int n, a[MAXN], c;
  int s[MAXN];
  void solve()
  {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
      scanf("%d", a + i);
    // read

    // if (n <= 15)
    // {
    c = INT_MIN;
    for (int state = 0; state < (1 << n); state++)
    {
      state <<= 1;
      for (int i = 1; i <= n; i++)
        s[i] = (state >> i) & 1;
      state >>= 1;
      // get color array
      int cur = 0;
      for (int i = 1; i <= n; i++)
      {
        int nearest = i - 1;
        while (nearest && s[i] != s[nearest])
          nearest--;
        if (a[i] == a[nearest])
          cur += a[i];
      }
      c = max(cur, c);
    }
    printf("%d\n", c);
    // } // n <= 15

    // else if (n <= 100)
    // {
    // } // n <= 100
  }
}

int main()
{
  freopen("color.in", "r", stdin);
  freopen("color.out", "w", stdout);
  scanf("%d", &T);
  while (T--)
    Solve::solve();
  fclose(stdin);
  fclose(stdout);
  return 0;
}